﻿package view.component
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.loader.*;
    import consts.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.system.*;
    import manager.*;
    import morn.core.components.*;
    import view.*;

    public class JhzButton extends ActiveButton
    {
        private var _jhzSprite:Sprite;
        private var img:Image;
        private var img_line:Image;
        private var imgMask:Sprite;
        private var ymMask:Sprite;
        private var _h:int;
        private var _total:int = 46;
        private var _startH:int = 51;
        private var _nowH:int = 0;
        private var cfgJuHunZhu:Object;
        private var _data:Object;
        private var exp:int;
        private var totalexp:int;
        private var loader:MovieResLoader;
        private var _eff:XMLMovieClip;
        private var _ymeff:XMLMovieClip;
        private var _tween:TweenMax;
        private var _bitmap:Bitmap;
        private var _cont:Sprite;
        public static const effXml:Class = JhzButton_effXml;
        public static const ymeffXml:Class = JhzButton_ymeffXml;

        public function JhzButton(param1:Object)
        {
            this.cfgJuHunZhu = ConfigDictionary.data.juhunzhu;
            super(param1);
            this._jhzSprite = new Sprite();
            this.addChildAt(this._jhzSprite, 0);
            this.imgMask = new Sprite();
            this.imgMask.graphics.beginFill(16777215, 1);
            this.imgMask.graphics.drawRect(0, 0, 60, 60);
            this.imgMask.graphics.endFill();
            this.imgMask.y = this._startH;
            this.imgMask.alpha = 0;
            this._jhzSprite.addChild(this.imgMask);
            this.ymMask = new Sprite();
            this.ymMask.graphics.beginFill(16777215, 1);
            this.ymMask.graphics.drawCircle(27, 26, 23);
            this.ymMask.graphics.endFill();
            this.ymMask.alpha = 0;
            this._jhzSprite.addChild(this.ymMask);
            this._jhzSprite.x = _btnMsg.sizeX * -35 * 0.8;
            this._jhzSprite.y = _btnMsg.sizeX * -35 * 0.8;
            this._jhzSprite.mouseChildren = false;
            this._jhzSprite.mouseEnabled = false;
            this._cont = new Sprite();
            this._cont.visible = false;
            this._bitmap = new Bitmap();
            this._bitmap.x = -27;
            this._bitmap.y = -26;
            this._bitmap.bitmapData = btn.skinbitmap;
            this._cont.addChild(this._bitmap);
            this.addChildAt(this._cont, 0);
            this._cont.x = this._jhzSprite.x + 27;
            this._cont.y = this._jhzSprite.y + 26;
            this._cont.mouseChildren = false;
            this._cont.mouseEnabled = false;
            this.visible = false;
            return;
        }// end function

        private function setH() : void
        {
            if (this.imgMask)
            {
                TweenLite.to(this.imgMask, 1.5, {y:this._nowH});
                if (this._ymeff)
                {
                    TweenLite.to(this._ymeff, 1.5, {y:this._nowH - 22});
                }
            }
            return;
        }// end function

        public function update(param1:Object) : void
        {
            var _loc_4:int = 0;
            if (this.visible == false)
            {
                this.visible = true;
            }
            this.showEff();
            var _loc_2:* = param1.id;
            var _loc_3:* = param1.state;
            this.exp = param1.exp;
            if (this.exp == 0)
            {
                this.doeff();
            }
            this._data = param1;
            this._data.type = 1;
            this._data.itemObj = ConfigDictionary.data.item[Constant.ITEM_JHZ];
            if (_loc_2 > 0 && _loc_3 == 1)
            {
                this.totalexp = this.cfgJuHunZhu[_loc_2].exp;
                _loc_4 = int(this._total * this.exp / this.totalexp);
                this._nowH = this._startH - _loc_4;
                this.setH();
                if (_loc_4 == this._total)
                {
                    addEffect();
                    this._data.eff = 1;
                    if (_loc_2 == 1 || _loc_2 == 2)
                    {
                        DialogMgr.instance.open(AppDialog.JUHUNZHU, this._data);
                    }
                }
                else
                {
                    this._data.eff = 0;
                    deleteEffect();
                }
            }
            return;
        }// end function

        override protected function doClick() : void
        {
            if (this._data && this._data.eff == 1)
            {
                DialogMgr.instance.open(AppDialog.JUHUNZHU, this._data);
            }
            else
            {
                WarningManager.show(130);
            }
            return;
        }// end function

        override protected function onRollMouse(event:MouseEvent) : void
        {
            var _loc_2:String = null;
            if (event.type == MouseEvent.ROLL_OVER)
            {
                _loc_2 = "已存入经验：<font color=\'#53b436\'>" + this.exp + "/" + this.totalexp + "</font>\n当你消灭怪物时，可额外将怪物的经验存入聚魂珠中<font color=\'#53b436\'>(VIP可免费双倍领取)</font>";
                ModelProxy.change("tips", "normal", {data:_loc_2, p:localToGlobal(new Point(mouseX, mouseY))});
            }
            else
            {
                ModelProxy.change("tips", "state", "close");
            }
            return;
        }// end function

        public function showEff() : void
        {
            this.loader = new MovieResLoader();
            if (this._eff == null)
            {
                this.loader.load(Config.getUrl("assets/images/activeButton/juhunzhu.swf", ResourceType.NORMAL), 3, this.loaded, 0);
            }
            return;
        }// end function

        private function loaded(param1:ApplicationDomain) : void
        {
            var _loc_2:XML = null;
            var _loc_3:XML = null;
            if (param1)
            {
                if (this._eff)
                {
                    if (this._eff.parent)
                    {
                        this._eff.parent.removeChild(this._eff);
                    }
                    this._eff.dispose();
                    this._eff = null;
                    if (this._ymeff.parent)
                    {
                        this._ymeff.parent.removeChild(this._ymeff);
                    }
                    this._ymeff.dispose();
                    this._ymeff = null;
                }
                _loc_2 = new XML(new effXml());
                this._eff = new XMLMovieClip("png.active.juhunzhu", _loc_2, null, true, param1);
                this._eff.mouseChildren = false;
                this._eff.mouseEnabled = false;
                this._eff.interval = int(1000 / 8);
                this._jhzSprite.addChild(this._eff);
                this._eff.mask = this.imgMask;
                _loc_3 = new XML(new ymeffXml());
                this._ymeff = new XMLMovieClip("png.active.juhunzhuym", _loc_3, null, true, param1);
                this._ymeff.y = 30;
                this._ymeff.mouseChildren = false;
                this._ymeff.mouseEnabled = false;
                this._ymeff.interval = int(1000 / 8);
                this._jhzSprite.addChild(this._ymeff);
                this._ymeff.mask = this.ymMask;
                this.setH();
            }
            return;
        }// end function

        public function doeff() : void
        {
            if (this._tween)
            {
                this._tween.kill();
            }
            this._cont.scaleX = 1;
            this._cont.scaleY = 1;
            this._cont.alpha = 0.6;
            this._cont.visible = true;
            this._tween = TweenMax.to(this._cont, 0.8, {scaleX:1.5, scaleY:1.8, repeat:2, alpha:0, onComplete:this.completeFunc, repeatDelay:1});
            return;
        }// end function

        private function completeFunc() : void
        {
            this._tween = null;
            this._cont.scaleX = 1;
            this._cont.scaleY = 1;
            this._cont.alpha = 0.6;
            this._cont.visible = false;
            return;
        }// end function

    }
}
